package org.ch02.job.test10;

import java.util.Map;

/**
 * @author XCH
 * @date 2025 - 03 - 19
 */
public class BuildFull {
    public static String buildFullSql(String sql, Map<String, Object> cond) {
        StringBuilder fullSql = new StringBuilder(sql);
        for (Map.Entry<String, Object> entry : cond.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            int paramIndex = fullSql.indexOf("?");
            if (paramIndex != -1) {
                if (value instanceof String) {
                    fullSql.replace(paramIndex, paramIndex + 1, "'" + value + "'");
                } else {
                    fullSql.replace(paramIndex, paramIndex + 1, value.toString());
                }
            }
        }
        return fullSql.toString();
    }
}
